import { Component } from '@angular/core';
import { Router} from '@angular/router';
import {Storage} from "@ionic/storage";
import{EventService}from'../services/event.service';

@Component({
  selector: 'app-tab3',
  templateUrl: 'tab3.page.html',
  styleUrls: ['tab3.page.scss']
})
export class Tab3Page {
  
  public isLoginEd:boolean = false;
  public username:string = '测试';

  constructor(public router:Router,public storage:Storage,public eventService: EventService) {}

  ngOnInit(){
    this.updateLoginInfo();
    this.eventService.event.on('login', () => {
      this.updateLoginInfo();
    })
  }

  updateLoginInfo(){
    this.storage.get('isLoginEd').then((val)=>{
      if (val == null){
        return;
      }
      this.isLoginEd = val;
      this.storage.get('USER_INFO').then((val)=>{
        this.username = val['username'];
      })
    })
  }


  // 进入所点击的页面
  showDetail(url:string){
    this.router.navigate(['/'+url]);
  }

  login(){
    this.router.navigate(['/login']);
  }

}
